package com.jiangjiang.eshop.promotion.controller;

import com.jiangjiang.eshop.order.dto.CouponDTO;
import com.jiangjiang.eshop.promotion.biz.PromotionBiz;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName PromotionController
 * @Description TODO
 * @Author jhw
 * @Date 2021/7/22 10:23
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/promotion")
public class PromotionController {

    @Autowired
    private PromotionBiz promotionBiz;

    /**
     * 查询用户可以使用的有效优惠券
     * @param userAccountId
     * @return
     */
    @GetMapping("/user/{userAccountId}")
    public List<CouponDTO> listValidByUserAccountId(
            @PathVariable("userAccountId") Long userAccountId) {
        try {
            return promotionBiz.listUnusedByUserAccountId(userAccountId);
        } catch (Exception e) {
            log.error("PromotionController listValidByUserAccountId error",e);
        }
        return new ArrayList<>();
    }
}
